import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from "@vitejs/plugin-vue-jsx";
// import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import ElementPlus from 'unplugin-element-plus/vite'

import { resolve } from 'path'; // 导入 path 模块 

// https://vitejs.dev/config/
export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
  const commonConfig = {
    resolve:{
      alias:{
        '@': resolve(__dirname, 'src'),   // 将 '@' 解析为 'src' 目录  
      }
    },
  }
  if (command === 'serve') {
    console.log('serve');
    return {
      define: {
        __APP_VERSION__: JSON.stringify('v1.0.0'),
        __API_URL__: JSON.stringify('api/v1'),
      },
      plugins: [
        vue(),
        vueJsx(), //插件使用
        ElementPlus()
        // AutoImport({
        //   resolvers: [ElementPlusResolver()],
        // }),
        // Components({
        //   resolvers: [ElementPlusResolver()],
        // }),
      ],
      server:{
        port:"8090"
      },
      ...commonConfig
    }
  } else {
    // command === 'build'
    console.log('build');
    return {
      plugins: [vue()],
      ...commonConfig
    }
  }
})
